package com;

import java.util.Arrays;
import java.util.Base64;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

public class ForLambda {
    public static void main(String[] args) {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7);

        System.out.println("---------jdk1.5之前---------");
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        System.out.println("---------jdk1.5---------");
        for (int i : list) {
            System.out.println(i);
        }

        System.out.println("---------jdk1.8---------");
        list.forEach(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) {
                System.out.println(integer);
            }
        });

        System.out.println("---------jdk1.8 lambda+函数式接口---------");
        list.forEach(integer -> System.out.println(integer));


        System.out.println("---------jdk1.8 方法引用+函数式接口---------");
        list.forEach(System.out::println);

        // 报错提示：Not a statement 译：不是一个声明
//        () -> System.out.println(1);
        // 报错提示：Not a statement
//        System.out::println;


        Consumer consumer1 = (i) -> System.out.println(1);
        Consumer consumer2 = System.out::println;

        Function<String, String> function = String::toUpperCase;
        System.out.println(function.getClass().getInterfaces()[0]);
    }

}
